const crypto = require('crypto')
// AES对称加密，加解密密钥相同
// 
const key = '7854156151111166';
const iv = '7445156151111166';
/**
 * @util 加密、解密工具类
 */
class CryptoUtil {

    /**
     * 解密
     * @param dataStr {string}
     */
    static Decrypt(dataStr) {
        let cipherChunks = [];
        let decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
        decipher.setAutoPadding(true);
        cipherChunks.push(decipher.update(dataStr, 'base64', 'utf8'));
        cipherChunks.push(decipher.final('utf8'));
        return cipherChunks.join('');
    }

    /**
     * 加密
     * @param dataStr {string}
     */
    static Encrypt(dataStr) {
        let cipherChunks = [];
        let cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
        cipher.setAutoPadding(true);
        cipherChunks.push(cipher.update(dataStr, 'utf8', 'base64'));
        cipherChunks.push(cipher.final('base64'));
        return cipherChunks.join('');
    }

    static RandomNum(){
        
    }
}

module.exports = CryptoUtil;
